package io.renren.modules.generator.controller;

import io.renren.common.utils.R;
import io.renren.constant.DeviceFinal;
import io.renren.modules.generator.service.IntellisenseStatsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Pattern;

/**
 * @ClassName IntellisenseStatsController
 * @Description TODO
 * @Author zhengd
 * @Date 2020/9/11 20:04
 * @Version 1.0
 **/
@RestController
@RequestMapping("deviceall/stats")
@Api("统计接口")
public class IntellisenseStatsController {

    @Autowired
    private IntellisenseStatsService intellisenseStatsService;

    @GetMapping("/quota")
    @ApiOperation("标准值")
    public R quota(@RequestParam(name = "type") String type,@RequestParam(name = "code",defaultValue = "") String code) {
        return R.ok().put("value", getIntellisenseStatsService().quota("hour", type, code));
    }

    @GetMapping("/water/detail")
    @ApiOperation("水质监控图表")
    public R waterDetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.water_type, DeviceFinal.waterQuotaMap));
    }

    @GetMapping("/water/avg")
    @ApiOperation("水质均值")
    public R waterAvg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.water_type, DeviceFinal.waterQuotaMap));
    }

    @GetMapping("/vocs/detail")
    @ApiOperation("挥发性有机物监控图表")
    public R vocsDetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.vocs_type, DeviceFinal.gasQuotaMap));
    }

    @GetMapping("/vocs/avg")
    @ApiOperation("挥发性有机物均值")
    public R vocsAvg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.vocs_type, DeviceFinal.gasQuotaMap));
    }

    @GetMapping("/tsp/detail")
    @ApiOperation("大气粉尘监控图表")
    public R tspDetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.tsp_type, DeviceFinal.tspQuotaMap));
    }

    @GetMapping("/tsp/avg")
    @ApiOperation("大气粉尘均值")
    public R tspAvg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.tsp_type, DeviceFinal.tspQuotaMap));
    }

    @GetMapping("/smoke/detail")
    @ApiOperation("烟气监控图表")
    public R smokeDetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.smoke_type ,DeviceFinal.smokeQuotaMap));
    }

    @GetMapping("/smoke/avg")
    @ApiOperation("烟气监控均值")
    public R smokeAvg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.smoke_type ,DeviceFinal.smokeQuotaMap));
    }

    @GetMapping("/sweage/detail")
    @ApiOperation("多普勒超声波流量计监控图表")
    public R sweageDetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.sweage_type ,DeviceFinal.sweageQuotaMap));
    }

    @GetMapping("/sweage/avg")
    @ApiOperation("多普勒超声波流量计均值")
    public R sweageAvg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.sweage_type ,DeviceFinal.sweageQuotaMap));
    }

    @GetMapping("/pm25/detail")
    @ApiOperation("大气颗粒物监控图表")
    public R pm25DetailChart(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("chartlist", getIntellisenseStatsService().statDetail(dateStr, DeviceFinal.pm25_type ,DeviceFinal.pm25QuotaMap));
    }

    @GetMapping("/pm25/avg")
    @ApiOperation("大气颗粒物均值")
    public R pm25Avg(@RequestParam(name = "date") String dateStr) {
        return R.ok().put("avg", getIntellisenseStatsService().statsAvg(dateStr, DeviceFinal.pm25_type ,DeviceFinal.pm25QuotaMap));
    }

    @GetMapping("/warning")
    @ApiOperation("预警分析接口")
    public R warning(@RequestParam(name = "date") String dateStr, String site, String code,
                     @RequestParam(value = "day",required = false,defaultValue = "false")
                     @Pattern(regexp = "true|false",message = "只允许输入true或false") String day) {
        if (Boolean.valueOf(day)) {
            return R.ok().put("warning", getIntellisenseStatsService().statWeekDetail(dateStr, site,code));
        } else {
            return R.ok().put("warning", getIntellisenseStatsService().statDetail(dateStr, site,code));
        }
    }

    public IntellisenseStatsService getIntellisenseStatsService() {
        return intellisenseStatsService;
    }
}
